from django.utils.deprecation import MiddlewareMixin
from django.contrib.auth import authenticate, login
from django.http import JsonResponse
from common.auth import Token


class JwtAuthorizationMiddleware(MiddlewareMixin):
	# def process_request(self, request): # noqa
	# 	pass
	
	def process_view(self, request, view_func, *args, **kwargs):  # noqa
		if getattr(view_func, 'login_exempt', False):
			return None
		if '/meida/' in request.path or '/admin/' in request.path:
			return None
		token = request.headers.get('Token')
		status, res = Token().verify_token(token)
		if not status:
			return JsonResponse(res)
		return None
